package com.jsoft.jsofted.platform.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.diboot.core.binding.annotation.BindEntityList;
import com.diboot.core.binding.annotation.BindField;
import com.gitee.sunchenbin.mybatis.actable.annotation.*;
import com.jsoft.jsofted.framework.entity.TimeEntity;
import com.jsoft.jsofted.framework.entity.TreeEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Id;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper = false)
@Table("dictionary")
@TableName("dictionary")
public class DicEntity implements TimeEntity, TreeEntity {
    @Column(length = 32)
    protected String tenantId;

    @Id
    @TableId(type = IdType.ASSIGN_ID)
    protected Long id;

    @Column(length = 50)
    @IsNotNull
    @Unique(value="nameCategory", columns = {"parent_id", "name", "category"})
    protected String name;

    // 字典类别字段
    @Column(length = 32)
    protected Long parentId;

    // folder——字典分类，dic——字典
    @Column(length = 8)
    @IsNotNull
    protected String category;

    /*字典条目字段*/
    @Column(length = 50)
    protected String type;

    @Column(length = 100)
    protected String itemName;

    @Column(length = 100)
    protected String itemValue;

    /*备用字段*/
    @Column(length = 100)
    protected String description;

    @Column(length = 200)
    protected String extdata;

    @Column
    protected Boolean isEditable;

    @Column
    protected Boolean isDeletable;

    @Column
    protected Boolean isDeleted;

    @Column
    @IsNotNull
    protected Timestamp createTime;

    @Column
    @IsNotNull
    protected Timestamp updateTime = new Timestamp(System.currentTimeMillis());

    @Column(length = 20, decimalLength = 6)
    @IsNotNull
    protected BigDecimal sortValue;

    @TableField(exist = false)
    @BindEntityList(entity = DicEntity.class, condition = "id=parent_id")
    protected List<DicEntity> items;

    @TableField(exist = false)
    @BindField(entity = DicEntity.class, field = "name", condition = "parent_id=id")
    protected String parentName;

}
